package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.mapper.AdminMapper;
import com.example.mybatisplus.mapper.AreaMapper;
import com.example.mybatisplus.model.domain.WhitelistSetting;
import com.example.mybatisplus.model.dto.PageDTO;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.AreaService;
import com.example.mybatisplus.model.domain.Area;
import org.springframework.stereotype.Controller;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2024-07-17
 * @version v1.0
 */
@RestController
@RequestMapping("/api/area")
public class AreaController {


    @Autowired
    private AreaService areaService;


    @GetMapping("pageList")
    public JsonResponse pageList(Area area, PageDTO dto){
        Page<Area> page=areaService.pageList(area,dto);
        return JsonResponse.success(page);
    }

    //修改房源信息
    @PostMapping("editArea")
    public JsonResponse editArea(@RequestBody Area area){
        boolean b=areaService.updateById(area);
        return JsonResponse.success(b);
    }
    @PostMapping("addArea")
    public JsonResponse addArea(@RequestBody Area area){
        boolean b = areaService.save(area); // 或者根据具体情况调用其他适合的方法进行保存操作
        return JsonResponse.success(b); // 返回操作是否成功的 JSON 响应
    }


    // 房源信息删除
    @PostMapping("removeArea")
    public JsonResponse removeArea(@RequestBody Area area){
        // b表示是否删除成功
        boolean res= areaService.removeArea(area);
        // res.data
        return JsonResponse.success(res);
    }

    // 强制房源信息删除
    @PostMapping("forceRemoveArea")
    public JsonResponse forceRemoveArea(@RequestBody Area area){
        // b表示是否删除成功
        boolean res= areaService.forceRemoveArea(area);
        // res.data
        return JsonResponse.success(res);
    }
    @GetMapping("/areanames")
    public ResponseEntity<List<String>> getAllAreaNames() {
        List<String> areaNames = areaService.getAllAreaNames();
        return ResponseEntity.ok(areaNames);
    }
}

